package demo1_enum;

/**
 * Created with IntelliJ IDEA.
 * Description: 枚举类，也会独立生成一个字节码文件
 * User: Gao zhao xu
 * Date: 2023-11-27
 * Time: 10:59
 */

/**
 * RED,BLACK,GREEN都是枚举对象
 * 枚举的构造方法默认是私有的
 */
public enum TestEnum {
    RED,BLACK,GREEN;

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (TestEnum x : testEnums){
            System.out.print(x + " " + x.ordinal() + " ");//索引位置
        }
        System.out.println();

        TestEnum testEnum = TestEnum.valueOf("GREEN");//将普通字符串转换成枚举实例
        System.out.println(testEnum);

        System.out.println(RED.compareTo(GREEN));//以索引位置进行减法
    }
    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case RED :
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
        }
    }
}
